
function createCommodityPanel() {
	var dataStore = Ext.create('Ext.data.Store', {
	    storeId:'universityStore',
	    fields:['id', 'title', 'catagory', 'pubacc', 'pubtime', 'state'],
	    data:{'items':[
	        { "id": 1, 'title':'adfa', 'catagory':'电脑硬件', 'pubacc':'117292775', "pubtime": '2008-10-28', 'state':'正在进行'},
	        { "id": 2, 'title':'adfa', 'catagory':'电脑硬件', 'pubacc':'117292775', "pubtime": '2008-10-28', 'state':'下架'}
	    ]},
	    proxy: {
	        type: 'memory',
	        reader: {
	            type: 'json',
	            root: 'items'
	        }
	    }
	});
	
	var dataStore2 = Ext.create('Ext.data.Store', {
	    storeId:'universityStore',
	    fields:['id', 'title', 'catagory', 'pubacc', 'pubtime', 'state'],
	    data:{'items':[
	        { "id": 1, 'title':'aaaaaa', 'catagory':'电脑硬件', 'pubacc':'117292775', "pubtime": '2008-10-28', 'state':'正在进行'},
	        { "id": 2, 'title':'aaaaaaaa', 'catagory':'电脑硬件', 'pubacc':'117292775', "pubtime": '2008-10-28', 'state':'下架'}
	    ]},
	    proxy: {
	        type: 'memory',
	        reader: {
	            type: 'json',
	            root: 'items'
	        }
	    }
	});
	
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });
	
	var rowEditing2 = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });
	
	
	
	var CommodityPanel = Ext.create('Ext.tab.Panel', {
		id: 'commodity-panel',
		
		iconCls: 'panel-title',

		layout: 'fit',
		
		activeTab: 0,
		
		items: [{
			title: '出售',
			layout: 'fit',
			items: Ext.create('Ext.grid.Panel', {
				id: 'soldPanelGrid',
			    store: dataStore,
			    tbar : Ext.create('Ext.toolbar.Toolbar', {
					items : [ {
						xtype : 'button',
						text : '添加',
						iconCls: 'icon-add',
						disabled: true
					}, {
						xtype : 'tbseparator'
					}, {
						id: 'soldp-removeButton',
						xtype : 'button',
						text : '删除',
						iconCls: 'icon-delete',
						disabled: true,
						handler: function() {
							Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
						}
					} ]
				}),
			    selModel: Ext.create('Ext.selection.CheckboxModel', {
			    	listeners: {
			            selectionchange: function(sm, selections) {
			                Ext.getCmp('soldp-removeButton').setDisabled(selections.length == 0);
			            }
			        }
			    }),
				plugins: [rowEditing],
				columnLines: true,
				fields:['id', 'title', 'catagory', 'pubacc', 'pubtime', 'state'],
			    columns: [
			         Ext.create('Ext.grid.RowNumberer'),
			        { header: 'ID',  dataIndex: 'id', width: 80 },
			        { header: '标题', dataIndex: 'title', field: 'textfield' },
			        { header: '类别', dataIndex: 'catagory', field: 'textfield' },
			        { header: '发布用户', dataIndex: 'pubacc', field: 'textfield' },
			        { header: '发布时间', dataIndex: 'pubtime', field: 'textfield' },
			        { header: '交易状态', dataIndex: 'state', field: 'textfield' },
			        {
			        	header: '操作',
			        	xtype:'actioncolumn', 
			        	width: 70,
			        	items: [{
			                icon: 'img/edit.png',
			                iconCls: 'cursor-pointer',
			                toolTip: '修改密码',
			                handler: function(grid, rowIndex, colIndex) {
			                    rowEditing.cancelEdit();
			                    rowEditing.startEdit(rowIndex, 0);
			                }
			            }]
			        }
			    ]})
			    
		},
		{
			title: '收购',
			layout: 'fit',
			items: Ext.create('Ext.grid.Panel', {
				id: 'purchasePanelGrid',
			    store: dataStore2,
			    tbar : Ext.create('Ext.toolbar.Toolbar', {
					items : [ {
						xtype : 'button',
						text : '添加',
						iconCls: 'icon-add',
						disabled: true
					}, {
						xtype : 'tbseparator'
					}, {
						id: 'purchasep-removeButton',
						xtype : 'button',
						text : '删除',
						iconCls: 'icon-delete',
						disabled: true,
						handler: function() {
							Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
						}
					} ]
				}),
			    selModel: Ext.create('Ext.selection.CheckboxModel', {
			    	listeners: {
			            selectionchange: function(sm, selections) {
			                Ext.getCmp('purchasep-removeButton').setDisabled(selections.length == 0);
			            }
			        }
			    }),
				plugins: [rowEditing2],
				columnLines: true,
				fields:['id', 'title', 'catagory', 'pubacc', 'pubtime', 'state'],
			    columns: [
			         Ext.create('Ext.grid.RowNumberer'),
			        { header: 'ID',  dataIndex: 'id', width: 80 },
			        { header: '标题', dataIndex: 'title', field: 'textfield' },
			        { header: '类别', dataIndex: 'catagory', field: 'textfield' },
			        { header: '发布用户', dataIndex: 'pubacc', field: 'textfield' },
			        { header: '发布时间', dataIndex: 'pubtime', field: 'textfield' },
			        { header: '交易状态', dataIndex: 'state', field: 'textfield' },
			        {
			        	header: '操作',
			        	xtype:'actioncolumn', 
			        	width: 70,
			        	items: [{
			                icon: 'img/edit.png',
			                iconCls: 'cursor-pointer',
			                handler: function(grid, rowIndex, colIndex) {
			                    rowEditing2.cancelEdit();
			                    rowEditing2.startEdit(rowIndex, 0);
			                }
			            }]
			        }
			    ]})
			    
		}]
	});
		
	return CommodityPanel;
}

function createCatagoryPanel() {
	Ext.define('Catagory', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'id', type: 'int'},
            {name: 'name', type: 'string'}
        ]
    });
	
	var dataStore = Ext.create('Ext.data.TreeStore', {
	    storeId:'catagoryStore',
	    model: 'Catagory',
	    proxy: {
	        type: 'ajax',
	        url: 'js/catagories.json'
	    },
	    folderSort: true
	});
	
	var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
        clicksToMoveEditor: 1,
        autoCancel: false
    });
	
	var tree = Ext.create('Ext.tree.Panel', {
		id: 'catagory-panel',
        title: '商品类别管理',
        collapsible: true,
        useArrows: true,
        rootVisible: false,
        store: dataStore,
        multiSelect: true,
        singleExpand: true,
        plugins: [rowEditing],
        tbar : Ext.create('Ext.toolbar.Toolbar', {
			items : [ {
				xtype : 'button',
				text : '添加',
				iconCls: 'icon-add',
				disabled: true
			}, {
				xtype : 'tbseparator'
			}, {
				id: 'soldp-removeButton',
				xtype : 'button',
				text : '删除',
				iconCls: 'icon-delete',
				disabled: true,
				handler: function() {
					Ext.MessageBox.confirm("Confirm", "确定删除所选的项吗?");
				}
			} ]
		}),
        columns: [{
            xtype: 'treecolumn', //this is so we know which column will show the tree
            text: '类别名称',
            width: 200,
            sortable: true,
            dataIndex: 'name'
        },{
        	header: '操作',
        	xtype:'actioncolumn', 
        	width: 70,
        	items: [{
                icon: 'img/edit.png',
                iconCls: 'cursor-pointer',
                handler: function(grid, rowIndex, colIndex) {
                    rowEditing.cancelEdit();
                    rowEditing.startEdit(rowIndex, 0);
                }
            }]
        }]
    });
	
	return tree;
}
